package com.tencent.mm.ui.base;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.Context;
import android.util.Log;

import com.tencent.mm.R;
import com.tencent.mm.compatible.util.UtilD;
import com.tencent.mm.sdk.platformtools.ad;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public final class BaseB {
    public interface a {
        void hm(boolean z);
    }

    static class b implements InvocationHandler {
        WeakReference<a> oap;

        @Override
        public final Object invoke(Object obj, Method method, Object[] objArr) {
            boolean z = false;
            if (this.oap == null) {
                Log.i("MicroMsg.ActivityUtil", "swipe invoke fail, callbackRef NULL!");
            } else {
                a aVar = this.oap.get();
                if (aVar == null) {
                    Log.i("MicroMsg.ActivityUtil", "swipe invoke fail, callback NULL!");
                } else {
                    if (objArr != null && objArr.length > 0 && (objArr[0] instanceof Boolean)) {
                        z = (Boolean) objArr[0];
                    }
                    aVar.hm(z);
                }
            }
            return null;
        }
    }

    public static boolean aET(String str) {
        return (aER(str) & 2) == 0;
    }

    private static int aER(String str) {
        Class aES = aES(str);
        if (aES != null) {
            return aV(aES);
        }
        return 0;
    }

    private static Class<?> aES(String str) {
        try {
            return Class.forName(str);
        } catch (Throwable e) {
            ad.printErrStackTrace("MicroMsg.ActivityUtil", e, "");
            ad.e("MicroMsg.ActivityUtil", "Class %s not found in dex", str);
            return null;
        }
    }

    public static boolean aEU(String str) {
        return (aER(str) & 4) != 0;
    }

    public static void ji(Context context) {
        if (!(context instanceof Activity)) {
            return;
        }
        ((Activity) context).overridePendingTransition(R.anim.ck, R.anim.s);
    }

    public static boolean aY(Class<?> cls) {
        return (aV(cls) & 2) == 0;
    }

    public static void jk(Context context) {
        if (!(context instanceof Activity)) {
            return;
        }
        ((Activity) context).overridePendingTransition(R.anim.s, R.anim.cp);
    }

    public static void jl(Context context) {
        if (!(context instanceof Activity)) {
            return;
        }
        ((Activity) context).overridePendingTransition(R.anim.s, R.anim.s);
    }

    public static String e(ComponentName componentName) {
        if (componentName.getClassName().startsWith(componentName.getPackageName())) {
            return componentName.getClassName();
        }
        return componentName.getPackageName() + componentName.getClassName();
    }


    public static boolean aX(Class<?> cls) {
        return (aV(cls) & 1) == 0;
    }

    public static int aV(Class<?> cls) {
        AnnotationA aVar = cls.getAnnotation(AnnotationA.class);
        if (aVar != null) {
            return aVar.value();
        }
        return aW(cls);
    }

    private static int aW(Class<?> cls) {
        Class superclass = cls.getSuperclass();
        if (superclass != null) {
            return aV(superclass);
        }
        return 0;
    }

    public static void bh(Activity activity) {
        try {
            Method declaredMethod = Activity.class.getDeclaredMethod("convertFromTranslucent");
            declaredMethod.setAccessible(true);
            declaredMethod.invoke(activity);
        } catch (Exception th) {
            th.printStackTrace();
        }
    }

    @TargetApi(16)
    public static void a(Activity activity, a aVar) {
        if (UtilD.kX(16)) {
            return;
        }
        try {
            Object newProxyInstance;
            Class[] declaredClasses = Activity.class.getDeclaredClasses();
            int length = declaredClasses.length;
            int i = 0;
            Class cls = null;
            while (i < length) {
                Class cls2 = declaredClasses[i];
                if (!cls2.getSimpleName().contains("TranslucentConversionListener")) {
                    cls2 = cls;
                }
                i++;
                cls = cls2;
            }
            if (aVar != null) {
                b bVar = new b();
                bVar.oap = new WeakReference<>(aVar);
                newProxyInstance = Proxy.newProxyInstance(cls.getClassLoader(), new Class[]{cls}, bVar);
            } else {
                newProxyInstance = null;
            }
            Method declaredMethod;
            if (UtilD.kX(21)) {
                declaredMethod = Activity.class.getDeclaredMethod("convertToTranslucent", cls);
                declaredMethod.setAccessible(true);
                declaredMethod.invoke(activity, newProxyInstance);
                return;
            }
            declaredMethod = Activity.class.getDeclaredMethod("convertToTranslucent", cls, ActivityOptions.class);
            declaredMethod.setAccessible(true);
            declaredMethod.invoke(activity, newProxyInstance, null);
        } catch (Exception th) {
            th.printStackTrace();
        }
    }
}
